const Koa = require('koa');
const Router = require('koa-router');

const app  = new Koa();

//子路由
let home = new Router();
home
    .get('/xgp',async (ctx) => {
       ctx.body = 'home xgp'
    })
    .get('/todo',async (ctx) => {
        ctx.body = 'home todo'
    });

let page = new Router();
page
    .get('/xgp',async (ctx) => {
        ctx.body = 'page xgp'
    })
    .get('/todo',async (ctx) => {
        ctx.body = 'page todo'
    });

//父级路由
let router = new Router();
router.use('/home',home.routes(),home.allowedMethods());
router.use('/page',page.routes(),page.allowedMethods());

app
    .use(router.routes())
    .use(router.allowedMethods());

// 监听端口
app.listen(3000,() => {
    //监听回调
    console.log('app is start at port 3000');
});
